import {expect} from "chai";
import { Mat3 } from "../src/Mat3";
import { Mat4 } from "../src/Mat4";
import { Quat } from "../src/Quat";
describe("Mat3", function () {
    before(function() {
        console.log("开始自动化测试Mat3...");
    });

    after(function() {
        console.log("结束...");
    });
    beforeEach(function() {
    });

    afterEach(function() {
    });
    it('#constructor', function () {
        let mat3=new Mat3();
        expect(mat3.equal([1,0,0,0,1,0,0,0,1])).to.equal(true);
    });
    it('#clone', function () {
        let mat3=new Mat3([1,1,1,1,1,1,1,1,1]);
        let b=mat3.clone();
        expect(b.equal(mat3)).to.equal(true);
    });
    it('#copy', function () {
        let mat3=new Mat3([1,1,1,1,1,1,1,1,1]);
        let b=new Mat3();
        b.copy(mat3);
        expect(b.equal(mat3)).to.equal(true);
    });
    it('#equal', function () {
        let mat3=new Mat3([1,1,1,1,1,1,1,1,1]);
        let b=new Mat3();
        b.copy(mat3);
        expect(b.equal(mat3)).to.equal(true);
    });
    it('#identity', function () {
        let mat3=new Mat3([1,1,1,1,1,1,1,1,1]);
        mat3.identity();
        expect(mat3.equal([1,0,0,0,1,0,0,0,1])).to.equal(true);
    });
    it('#transpose', function () {
        let mat3=new Mat3([1,2,3,4,5,6,7,8,9]);
        mat3.transpose();
        expect(mat3.equal([1,4,7,2,5,8,3,6,9])).to.equal(true);
    });
    it('#invert', function () {
        let mat3=new Mat3([1,0.5,0,0,1,0,0,0,1]);
        mat3.invert();       
        expect(mat3.equal([1,-0.5,0,0,1,0,0,0,1])).to.equal(true);
    });
    it('#adjoint', function () {
        let mat3=new Mat3([1,0.5,0,0,1,0,0,0,1]);
        mat3.adjoint();       
        expect(mat3.equal([1,-0.5,0,0,1,0,0,0,1])).to.equal(true);
    });
    it('#determinant', function () {
        let mat3=new Mat3([1,0.5,0,0,1,0,0,0,1]);
        let out=mat3.determinant();       
        expect(out).to.equal(1);
    });
    it('#multiply', function () {
        let left=new Mat3([1,0.5,0,0,1,0,0,0,1]);
        let right=new Mat3([2,0.5,0,0,1,0,0,0,1]);
        left.multiply(right);
        expect(left.equal([2,1.5,0,0,1,0,0,0,1])).to.equal(true);
    });
    it('#premultiply', function () {
        let left=new Mat3([1,0.5,0,0,1,0,0,0,1]);
        let right=new Mat3([2,0.5,0,0,1,0,0,0,1]);
        left.premultiply(right);
        expect(left.equal([2,1,0,0,1,0,0,0,1])).to.equal(true);
    });
    it('#scale', function () {
        let left=new Mat3([1,0.5,0,0,1,0,0,0,1]);
        left.scale([2,1]);
        expect(left.equal([2,1,0,0,1,0,0,0,1])).to.equal(true);
    });
    it('#rotate', function () {
        let left=new Mat3([1,0.5,0,0,1,0,0,0,1]);
        left.rotate(Math.PI/3);
        expect(left.equal([0.5,1.116025447845459,0,-0.8660253882408142,0.0669872984290123,0,0,0,1])).to.equal(true);
    });
    it('#translate', function () {
        let left=new Mat3([1,0.5,0,0,1,0,0,0,1]);
        left.translate([1,2]);
        expect(left.equal([1,0.5,0,0,1,0,1,2.5,1])).to.equal(true);
    });
    it('#fromMat4', function () {
        let left=new Mat4([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
        let out=new Mat3();
        out.fromMat4(left);        
        expect(out.equal([1,2,3,5,6,7,9,10,11])).to.equal(true);
    });
    it('#fromQuat', function () {
        let quat=new Quat([0.2,0.3,1,1]);
        let out=new Mat3();
        out.fromQuat(quat);        
        expect(out.equal([-1.1800000667572021,2.120000123977661,-0.20000001788139343,
            -1.8799999952316284,-1.0800000429153442,1,
            1,0.20000001788139343,0.7400000095367432])).to.equal(true);
    });
    it('#fromTranslation', function () {
        let out=new Mat3();
        out.fromTranslation([2,3]);        
        expect(out.equal([1,0,0,0,1,0,2,3,1])).to.equal(true);
    });
    it('#fromScaling', function () {
        let out=new Mat3();
        out.fromScaling([2,3]);   
        console.log(out);
             
        expect(out.equal([2,0,0,0,3,0,0,0,1])).to.equal(true);
    });
    it('#fromRotation', function () {
        let out=new Mat3();
        out.fromRotation(Math.PI/3);        
        expect(out.equal([0.5,0.8660253882408142,0,-0.8660253882408142,0.5,0,0,0,1])).to.equal(true);
    });
    it('#normalFromMat4', function () {
        let left=new Mat4();
        left.fromRotation(Math.PI/3,[1,0,0]);
        let out=new Mat3();
        out.normalFromMat4(left);        
        expect(out.equal([1,0,0,0,0.5,0.8660253882408142,0,-0.8660253882408142,0.5])).to.equal(true);
    });
    it('#projection', function () {
        let left=new Mat3();
        left.projection(10,10);     
        expect(left.equal([0.20000000298023224,0,0,0,-0.20000000298023224,0,-1,1,1])).to.equal(true);
    });
    it('#toString', function () {
        let left=new Mat3();
        let a=left.toString();
        expect(a).to.equal('Mat3(1,0,0,0,1,0,0,0,1)');
    });
})